package com.yfux._05_tlias.controller;

import com.yfux._05_tlias.pojo.Result;
import com.yfux._05_tlias.util.OssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/upload")
public class FileUploadController {
    @Autowired
    OssUtil ossUtil;

    @PostMapping
    public Result upload(MultipartFile image) {
        log.info("上传文件: {}", image);
        String url = ossUtil.uploadFile(image);
        return url != null ? Result.success(url) : Result.error("上传文件" + image + "失败");
    }
}
